package com.example.controller;

import com.example.interceptor.Auth;
import com.example.model.Course;
import com.example.service.CourseService;
import com.example.util.DataMap;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: tao95
 * Date: 2017/5/9
 * Time: 19:59
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Auth
@Controller
@RequestMapping("course")
@Api(value = "course",tags = "课程管理类")
public class CourseController {
    @Autowired
    private CourseService courseServiceImpl;
    @RequestMapping(value = "/addCourse",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = {RequestMethod.POST})
    @ApiOperation("添加管理员接口")
    public String  addAdmin(
            @ApiParam(name = "Course",value = "课程",required = true) Course course,
            HttpServletRequest request){
        ModelAndView model = new ModelAndView();
        DataMap dataMap = courseServiceImpl.insertCourse(course);
        if((Integer)dataMap.get("code") == 10000){
            model.addObject("addCourse","success");
        }else{
            model.addObject("addCourse","Fail");
        }
        return "forward:/courseList";
    }
    @RequestMapping(value = "/delCourse",produces = MediaType.APPLICATION_JSON_UTF8_VALUE,method = {RequestMethod.GET})
    @ApiOperation("删除课程接口")
    public String  delCourse(
            @ApiParam(name = "id",value = "课程id",required = true) Integer id,
            HttpServletRequest request){
        ModelAndView model = new ModelAndView();
        DataMap dataMap = courseServiceImpl.delCourse(id);
        if((Integer)dataMap.get("code") == 10000){
            model.addObject("delCourse","success");
        }else{
            model.addObject("delCourse","Fail");
        }
        return "forward:/courseList";
    }

}